#include <iostream>

using namespace std;

const int N = 1e4 + 10;

int p[N];
int n, m;

int find(int x)
{
	if (p[x] != x) p[x] = find(p[x]);
	return p[x];
}

int main()
{
	cin >> n >> m;
	
	for (int i = 1; i <= n; i ++ ) p[i] = i;
	
	while (m -- )
	{
		int op, a, b;
		cin >> op >> a >> b;
		
		int pa = find(a), pb = find(b);
		
		if (op == 1)
		{
			if (pa == pb) continue;
			
			p[pa] = pb;
		}
		else cout << (pa == pb ? "Y" : "N") << endl;
	}
	
	return 0;
	
}